﻿using UnityEngine;
using UnityEngine.UI;

namespace JH
{
    /// <summary>
    ///  图表中任意继承自MaskableGraphic的组件的基类
    /// </summary>
    [RequireComponent(typeof(CanvasRenderer))]
    public abstract class BasicGraphic<TPoint> : MaskableGraphic, IChartBase
        where TPoint : struct
    {
        /// <summary>
        ///  图表实例
        /// </summary>
        private IChart<TPoint> _chart;

        /// <summary>
        ///  获取当前图表组件的图表
        /// </summary>
        public IChart<TPoint> Chart => _chart ??= this.GetChart<TPoint>();

#if UNITY_EDITOR
        protected override void OnValidate()
        {
            this.SetRectTransform();
            base.OnValidate();

            Chart?.Refresh();
        }
#endif
    }
}